use serde::Serialize;
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsValue;

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(js_namespace = ["window", "__TAURI__", "window", "getCurrentWindow()"])]
    pub async fn minimize();

    #[wasm_bindgen(js_namespace = ["window", "__TAURI__", "window", "getCurrentWindow()"])]
    pub async fn toggleMaximize();

    #[wasm_bindgen(js_namespace = ["window", "__TAURI__", "window", "getCurrentWindow()"])]
    pub async fn isMaximized() -> JsValue;
    
    #[wasm_bindgen(js_namespace = ["window", "__TAURI__", "window", "getCurrentWindow()"])]
    pub async fn close();

    #[wasm_bindgen(js_namespace = ["window", "__TAURI__", "core"])]
    pub async fn invoke(cmd: &str, args: JsValue);
}

/// 判断当前是否运行在Tauri环境中
pub fn is_tauri_env() -> bool {
    tauri_wasm::is_tauri()
}

pub fn to_js_value<T: Serialize>(args: &T) -> Result<JsValue, serde_wasm_bindgen::Error> {
    serde_wasm_bindgen::to_value(args)
}